﻿<div ms-controller="YGFL">

    <div class="default-tab ft14 ">
        <table class="table table-striped table-responsive table-hover">
            <thead>
                <tr>
                    <th>名称</th>
                    <th>金额(元)</th>
                    <th>规则</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-item="tmpListData">
                    <td>{{item.Name}}</td>
                    <td>{{item.Amount}}</td>
                    <td>{{GetTypeName(item.Rules)}}</td>
                    <td>
                        <a class="cz-btn ft18 sc-color tip" data-toggle="tooltip" title="删除" ms-click="delfl(item,$event)">
                            <i class="iconfont icon-shanchu"></i>
                        </a>
                    </td>
                </tr>
            </tbody>
            <tfoot>
                <tr style="border-bottom: 1px solid #ddd;">
                    <td>
                        <input type="text" class="form-control" ms-duplex="FLItem.Name" placeholder="名称"></td>
                    <td>
                        <input type="text" class="form-control" ms-duplex="FLItem.Amount" placeholder="金额(元)"></td>
                    <td>
                        <select class="form-control" ms-duplex="FLItem.Rules">
                            <option value="1">当月全勤发放</option>
                            <option value="2">按月发放</option>
                            <option value="3">出勤率 * 金额</option>
                            <option value="4">出勤天数 * 金额</option>
                            <option value="5">出差天数 * 金额</option>
                        </select>
                    </td>
                    <td>
                        <a class="cz-btn ft18 tip" data-toggle="tooltip" title="添加" ms-click="addfl()">
                            <i class="iconfont icon-jiahao ft14"></i>
                        </a>
                    </td>
                </tr>
            </tfoot>
        </table>
    </div>

    <div style="text-align: center">
        <button type="button" class="btn btn-info btn-lg" ms-click="AddYGFL()"><i class="iconfont icon-jiahao ft12 mr5"></i>保存数据</button>
    </div>

</div>


<script>
    var processId = model.SelModel.PDID;
    var tempindex = avalon.define({
        $id: "YGFL",
        tmpListData: [],
        nowmodel: model.SelModel,
        FLItem: { Name: "", Amount: "", Rules: "" },
        addfl: function () {
            if (!tempindex.FLItem.Name) {
                ComFunJS.winwarning("请输入名称");
                return;
            }
            if (!tempindex.FLItem.Amount) {
                ComFunJS.winwarning("请输入金额");
                return;
            }
            else {
                var reg = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
                if (!reg.test(tempindex.FLItem.Amount)) {
                    ComFunJS.winwarning("金额格式错误,保留2位小数");
                    return;
                }
            }
            if (!tempindex.FLItem.Rules) {
                ComFunJS.winwarning("请选择规则");
                return;
            }

            tempindex.tmpListData.push($.extend({}, tempindex.FLItem.$model));

            tempindex.FLItem.Name = "";
            tempindex.FLItem.Amount = "";
            tempindex.FLItem.Rules = "";

        },
        delfl: function (item) {
            if (event) {
                event.stopPropagation();
            }

            tempindex.tmpListData.remove(item);
        },
        AddYGFL: function () {
            var modelValue;
            modelValue = tempindex.tmpListData.size() > 0 ? JSON.stringify(tempindex.tmpListData.$model) : "";

            $.post("/API/VIEWAPI.ashx", { Action: "XZGL_ADDFL", P1: modelValue }, function (result) {
                if (result.ErrorMsg == "") {

                    ComFunJS.winsuccess("保存成功");
                }
            });
        },
        GetTypeName: function (nodeType) {
            var nodeName = "";
            switch (nodeType + '') {
                case '1': nodeName = "当月全勤发放"; break;
                case '2': nodeName = "按月发放"; break;
                case '3': nodeName = "出勤率 * 金额"; break;
                case '4': nodeName = "出勤天数 * 金额"; break;
                case '5': nodeName = "出差天数 * 金额"; break;
            }
            return nodeName;
        },
        InitWigetData: function () {

            //编辑加载数据
            $.getJSON('/API/VIEWAPI.ashx?Action=XZGL_GETFLLIST', {}, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    if (resultData.Result.length > 0) {
                        tempindex.tmpListData = resultData.Result;
                    }
                }
            })

        }
    })
    //# sourceURLFL.js;
</script>
